  import { Injectable } from '@angular/core';
  import { EntityConfig } from '../../core/entity-config.types';
  import { SaleOrderDto } from '../../proxy/joy/erp/basic-archives/sales';
  import { DatePipe } from '@angular/common';
  import { LocalizationService } from '@abp/ng.core';
  import { DocumentStatus } from '../../proxy/joy/erp/basic-archives/core/document-status.enum';

  @Injectable({
    providedIn: 'root'
  })
  export class SaleOrderConfigService {
    datePipe = new DatePipe('zh-CN');

    constructor(
      private localizationService: LocalizationService
    ) {}

    getConfig(): EntityConfig {
      return {
        entityType: 'Joy.Erp.BasicArchives.Sales.SaleOrder',
        propertys: [
          {
            name: 'Code',
            key: 'code',
            type: 'string',
            field: (item: SaleOrderDto) => item.code,
            width: 200,
            show: true,
            order: 0,
            fixed: 0
          },
          {
            name: 'OrderType',
            key: 'orderType',
            type: 'string',
            field: (item: SaleOrderDto) => item.orderType?.displayName || '',
            width: 150,
            show: true,
            order: 1,
            fixed: 0
          },
          {
            name: 'Customer',
            key: 'customer',
            type: 'string',
            field: (item: SaleOrderDto) => item.customer?.name || '',
            width: 200,
            show: true,
            order: 2,
            fixed: 0
          },
          {
            name: 'Operator',
            key: 'operator',
            type: 'string',
            field: (item: SaleOrderDto) => item.operator?.name || '',
            width: 120,
            show: true,
            order: 3,
            fixed: 0
          },
          {
            name: 'BusinessDate',
            key: 'businessDate',
            type: 'date',
            field: (item: SaleOrderDto) => this.datePipe.transform(item.businessDate, 'yyyy-MM-dd'),
            width: 150,
            show: true,
            order: 4,
            fixed: 0
          },
          {
            name: 'DocumentStatus',
            key: 'documentStatus',
            type: 'string',
            field: (item: SaleOrderDto) => this.l('BasicArchives::EnumText:Joy.Erp.BasicArchives.Core.DocumentStatus.' + DocumentStatus[item.documentStatus]),
            width: 120,
            show: true,
            order: 5,
            fixed: 0
          },
          {
            name: 'Mark',
            key: 'mark',
            type: 'string',
            field: (item: SaleOrderDto) => item.mark,
            width: 200,
            show: true,
            order: 6,
            fixed: 0
          },
          {
            name: 'CreationTime',
            key: 'creationTime',
            type: 'date',
            field: (item: SaleOrderDto) => this.datePipe.transform(item.creationTime, 'yyyy-MM-dd'),
            width: 150,
            show: true,
            order: 7,
            fixed: 0
          },
        ]
      };
    }

    private l(key: string, ...parmas: string[]): string {
      return this.localizationService.instant(key, ...parmas);
    }  
  }
